package com.kefu.call.vo;

import org.apache.commons.lang3.StringUtils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.kefu.common.context.KefuContext;
import com.kefu.common.vo.AbstractSearchVo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

/**
 * @author francis
 * @date 2021/05/22
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@ApiModel(description = "活动清单")
public class ActivityInventoryInfoSearchVo extends AbstractSearchVo {
    @ApiModelProperty(value = "活动ID")
    private String activityId;

    @ApiModelProperty(value = "清单名称")
    private String inventoryName;

    @ApiModelProperty(value = "创建时间开始")
    private Long createTimeStart;

    @ApiModelProperty(value = "创建时间结束")
    private Long createTimeEnd;

    @ApiModelProperty(value = "创建人")
    private String createUser;

    @ApiModelProperty(value = "修改时间开始")
    private Long updateTimeStart;

    @ApiModelProperty(value = "修改时间结束")
    private Long updateTimeEnd;

    @ApiModelProperty(value = "修改人")
    private String updateUser;

    @ApiModelProperty(value = "数据状态0 无效，1有效")
    private Integer dataStatus = 1;

    @ApiModelProperty(value = "租户")
    private String tenantId;

    @ApiModelProperty(value = "所属用户")
    private String userId;

    @ApiModelProperty(value = "所属用户")
    private String userName;

    @ApiModelProperty(value = "清单状态",example="1",allowableValues="1,2",notes="1 未完成，2已完成")
    private Integer inventoryStatus;
    
    @ApiModelProperty(value = "清单分配状态",example="1",allowableValues="1,2",notes="1 未分配，2已分配")
    private Integer assignmentStatus;
    
    @ApiModelProperty(value = "意向状态",example="0",allowableValues="0,1,2,3,4",notes="0 无，1 无效电话，2无意向，3 意向，4已成交")
    private Integer intentionStatus;

    @ApiModelProperty(value = "客户ID")
    private String customerId;

    @ApiModelProperty(value = "客户名称")
    private String customerName;

    @ApiModelProperty(value = "预约时间开始")
    private Long reserveTimeStart;

    @ApiModelProperty(value = "预约时间结束")
    private Long reserveTimeEnd;

    @ApiModelProperty(value = "联系计划ID")
    private String planId;


    public <T>QueryWrapper<T> builder() {
  		QueryWrapper<T> wrapper=Wrappers.query();
	    if (StringUtils.isNotBlank(activityId)) {
	        wrapper.eq("activity_id", activityId);
	    }
	    if (StringUtils.isNotBlank(inventoryName)) {
	        wrapper.eq("inventory_name", inventoryName);
	    }
	    if (createTimeStart != null) {
		    wrapper.ge("create_time", createTimeStart);
		}
		if (createTimeEnd != null) {
		    wrapper.le("create_time", createTimeEnd);
		}
	    if (StringUtils.isNotBlank(createUser)) {
	        wrapper.eq("create_user", createUser);
	    }
		if (updateTimeStart != null) {
		    wrapper.ge("update_time", updateTimeStart);
		}
		if (updateTimeEnd != null) {
		    wrapper.le("update_time", updateTimeEnd);
		}
	    if (StringUtils.isNotBlank(updateUser)) {
	        wrapper.eq("update_user", updateUser);
	    }
		if (dataStatus != null) {
		    wrapper.eq("data_status", dataStatus);
		}
	    if (StringUtils.isNotBlank(tenantId)) {
	        wrapper.eq("tenant_id", tenantId);
	    }
	    if (StringUtils.isNotBlank(userId)) {
	        wrapper.eq("user_id", userId);
	    }
	    if (StringUtils.isNotBlank(userName)) {
	    	wrapper.like("user_name", userName);
	    }
		if (inventoryStatus!=null) {
		    wrapper.eq("inventory_status", inventoryStatus);
		}
		if (intentionStatus!=null) {
			wrapper.eq("intention_status", intentionStatus);
		}
		if (assignmentStatus!=null) {
			wrapper.eq("assignment_status", assignmentStatus);
		}
	    if (StringUtils.isNotBlank(customerId)) {
	        wrapper.eq("customer_id", customerId);
	    }
	    if (StringUtils.isNotBlank(customerName)) {
	        wrapper.like("customer_name", customerName);
	    }
	    if (reserveTimeStart != null) {
		    wrapper.ge("reserve_time", reserveTimeStart);
		}
		if (reserveTimeEnd != null) {
		    wrapper.le("reserve_time", reserveTimeEnd);
		}
	    if (StringUtils.isNotBlank(planId)) {
	        wrapper.eq("plan_id", planId);
	    }
	    wrapper.eq("tenant_id", KefuContext.getKefuContext().getTenantId());
	    return wrapper;
	}
}